package com.shengwei.truck.driver.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.shengwei.truck.driver.bean.MyConstant;
import com.shengwei.truck.driver.socket.SocketManager;
import com.shengwei.truck.driver.utils.AlarmManagerUtils;
import com.shengwei.truck.driver.utils.MyLogFile;


public class AlarmHeartReceiver extends BroadcastReceiver {
    public static long lastSendTime =  0;
    @Override
    public void onReceive(Context context, Intent intent) {
        switch(intent.getAction()) {
            case MyConstant.ALARM_HEART_BROADCAST: {
                //这里还是主线程,threadId与MainActivity的onCreate函数中的threadId相等
                float interval = ( (System.currentTimeMillis() - lastSendTime)/1000 ) / 60.0f;
                lastSendTime = System.currentTimeMillis();
                MyLogFile.i("AlarmHeartReceiver","AlarmHeartReceiver SocketService run for heart pack  interval min="+interval+",threadId="+Thread.currentThread().getId());
                SocketManager.getInstance(context).sendHeart();
                AlarmManagerUtils.getInstance(context).getUpAlarmManagerWorkOnReceiver();
                break;
            }
        }
    }
}